﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Common;
using KendoMvcUI.Core;
using KendoMvcUI.Enums;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class Calendar:KendoUIBase
    {
        public Calendar(KendoUIControlSettings settings,
            ViewContext viewContext,IViewDataContainer viewDataContainer)
            :base(settings,viewContext,viewDataContainer)
        { }
        public override string RenderHtml()
        {
            return "<div id=\"{0}\"></div>".Formator(Settings.Id);
        }
    }
    public class CalendarSettings:KendoUIControlSettings
    {
        public CalendarSettings()
            :base("kendoCalendar")
        { }

        #region 属性
        public string Culture { get; set; }
        public DateDepth? Depth { get; set; }
        /// <summary>
        /// "Taday- #: kendo.toString(data, "d") #"
        /// </summary>
        public string Footer { get; set; }
        /// <summary>
        /// MM/dd/yyyy
        /// </summary>
        public string Format { get; set; }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public DateTime? Max { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public DateTime? Min{ get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateDepth? Start { get; set; }
        /// <summary>
        /// Specifies the selected date.
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript=true)]
        public DateTime? Value { get; set; }
        #endregion
        #region 事件
        [PropertySetting(IsIngoreForJavaScript=true)]
        public string OnChange { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript=true)]
        public string OnNavigate { get; set; }
        #endregion

        public override string ToJsSettings()
        {
            var js=base.ToJsSettings();
            if (!js.EndsWith(","))
                js += ",";

            if (Max.HasValue)
                js += "max:new Date({0},{1},{2}),".Formator(Max.Value.Year,Max.Value.Month-1,Max.Value.Day);
            if (Min.HasValue)
                js += "min:new Date({0},{1},{2}),".Formator(Min.Value.Year, Min.Value.Month-1, Min.Value.Day);
            if (Value.HasValue)
                js += "value:new Date({0},{1},{2}),".Formator(Value.Value.Year, Value.Value.Month-1, Value.Value.Day);

            if (!OnChange.IsNullOrWhiteSpace())
                js += "change:{0},".Formator(OnChange);
            if (!OnNavigate.IsNullOrWhiteSpace())
                js += "navigate:{0},".Formator(OnNavigate);
            return js.TrimEnd(',');
        }
    }
}
